package domain

import (
	"context"

	"gitee.com/linxing_3/sr-core/domain"
)

type DomainInjectFNE func(context.Context) (domain.IDomain, error)
type DomainInjectFN func(context.Context) domain.IDomain

type DomainInject struct {
	Name        string
	Description string
	FactoryE    DomainInjectFNE
	Factory     DomainInjectFN
}

func (f DomainInject) Gen(ctx context.Context) (domain.IDomain, error) {
	if f.FactoryE != nil {
		return f.FactoryE(ctx)
	}
	return f.Factory(ctx), nil
}

var buildInjectDomains = []*DomainInject{}

// RegisterDomainInject 注册域注入
func RegisterDomainInject(f *DomainInject) {
	buildInjectDomains = append(buildInjectDomains, f)
}

func GetDomainsInject() []*DomainInject {
	return buildInjectDomains
}
